package com.group3.merchant.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtil {
	public static String reqLogin(String mid) throws IOException {
		URL url = new URL(
				"http://10.222.29.166:8080/amc_admin/TypeServlet?mId=" + mid);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		String type = null;
		conn.setRequestMethod("GET");
		conn.setDoInput(true);
		conn.setDoOutput(true);
		try {
			conn.connect();
		} catch (ConnectException e) {
			e.printStackTrace();
			return null;
		}
		

		// 获取
		int resp = conn.getResponseCode();
		System.out.println(resp);
		if (resp == 200) {
			InputStream is = conn.getInputStream();

			byte[] buff = new byte[1024];
			int len = -1;
			while ((len = is.read(buff)) != -1) {
				type = new String(buff, 0, len);

			}
			System.out.println(type);
		} else {
			System.out.println("request fail!!!");
		} 
		return type;

	}

	public static void main(String[] args) {
		try {
			HttpUtil.reqLogin("c44a7b53-e849-4236-948b-077289a481c6");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
